package com.badibadi.activity;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.badibadi.abcpinying.SortModel;
import com.badibadi.mytools.CalendarTools;
import com.badibadi.uniclubber.R;
import com.badibadi.uniclubber.R.id;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnLayoutChangeListener;
import android.view.ViewTreeObserver;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class PinyinChoiceTheTransferObjectActivity extends ChoiceCrewActivity {

	ListView lv;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		init();
	}
    
	private void init() {
		// TODO Auto-generated method stub
		lv=(ListView)this.findViewById(R.id.country_lvcountry);
		this.findViewById(R.id.quanxuan_quanbuxuan).setVisibility(View.GONE);
		this.findViewById(R.id.line2).setVisibility(View.GONE);
		((TextView)(this.findViewById(R.id.title))).setText(getResources().getString(R.string.PleaseSelectATransferObject));
		final LinearLayout ll=(LinearLayout)this.findViewById(R.id.choice_crew_ll);
//		   
		
		FrameLayout fr_l=(FrameLayout)this.findViewById(R.id.fr_ll);
		fr_l.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
			
			@Override
			public void onGlobalLayout() {
				// TODO Auto-generated method stub
				ll.setGravity(Gravity.TOP);		
				ll.setLayoutParams(new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
			}
		});
		
		Button finishbtn=(Button)this.findViewById(R.id.Finish_btn);
		finishbtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent =new Intent(PinyinChoiceTheTransferObjectActivity.this,AfterLandingActivity.class);
				Iterator iterator=getAdapter().getMap().entrySet().iterator();
				SortModel sortmodel=null;
				while(iterator.hasNext())
				{
				   Map.Entry entry=(Map.Entry)iterator.next();
				   sortmodel=(SortModel) entry.getValue();
				   break;
				}
				if(sortmodel!=null)
				{
			    	intent.putExtra("result", sortmodel);
				    setResult(1,intent);
				    finish();
				}
				else
				{
					ShowToast(getApplicationContext(), getResources().getString(R.string.l_xb123));
				}
			}
		});
		finishbtn.setText(R.string.OkEnglish);
		finishbtn.setBackgroundResource(R.drawable.shape_btn_green_button);
		
		
	
	}
	/**
	 * 将button上的显示数据弄掉
	 */
	@Override
	protected void setButtonUpNumber() {
		// TODO Auto-generated method stub
		
	}

	/**
	 * 重写点击listView后的侦听
	 */
	@Override
	protected void initsortListViewClistener() {
		// TODO Auto-generated method stub
		
		getSortListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View view, int position,
					long id) {
				// TODO Auto-generated method stub
				
				Map<Integer, Object> map=new HashMap<Integer, Object>();
				map.put(position, getAdapter().getItem(position));
				getAdapter().setMap(map);
				getAdapter().notifyDataSetChanged();
			}
		});
	}
	/**
	 * 重写数据
	 */
	@Override
	protected void initData() {
		// TODO Auto-generated method stub
		super.initData();
	}
	
}
